package com.service;

import com.dto.DeptDto;
import com.dto.UserDto;
import com.mapper.DeptMapper;
import com.mapper.UserMapper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class SystemService {

    private final UserMapper userMapper;
    private final DeptMapper deptMapper;

    public SystemService(UserMapper userMapper, DeptMapper deptMapper) {
        this.userMapper = userMapper;
        this.deptMapper = deptMapper;
    }

    @Transactional
    public void addUserWithDept(UserDto userDto,String deptName){
        DeptDto deptDto = new DeptDto(userDto.getDeptId(), deptName);
        userMapper.addUser(userDto);
        deptMapper.addDept(deptDto);


    }

    public List<UserDto> userPage() {
        return userMapper.page();
    }

    public List<DeptDto> deptPage() {
        return deptMapper.page();
    }
}
